﻿package com.javaPattern.DynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class PassengerProxy2 implements InvocationHandler {
	public Object obj;

	// 把obj交给代理类
	public Object setObj(Object obj) {
		this.obj = obj;
		return Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj
				.getClass().getInterfaces(), this);
	}

	@Override
	public Object invoke(Object arg0, Method method, Object[] args)
			throws Throwable {
		System.out.println("再去火车站");
		method.invoke(obj, args);
		System.out.println("从火车站返回");
		return obj;
	}

}
